<?php

namespace backend\controllers;

/**
 * @author  shuang
 * @date    2016-11-17 13:34:38
 * @version V1.0
 * @desc    
 */
use common\components\BController;
use backend\models\MY_TaskArea;
use common\components\MTools;
use yii\helpers\Json;
use yii\helpers\ArrayHelper;
use Yii;

class TaskareaController extends BController {

    public function actions() {
        return [
            "list" => [
                "class" => "\common\actions\ListAction",
                "modelClass" => new MY_TaskArea()
            ],
            "create" => [
                "class" => "\common\actions\CreateAction",
                "modelClass" => new MY_TaskArea(),
                "renderParams" => ["action" => "create"],
            ],
            "update" => [
                "class" => "\common\actions\UpdateAction",
                "modelClass" => new MY_TaskArea(),
                "renderParams" => ["action" => "update"],
                "renderTo" => "create",
                "redirectTo" => "list",
                "redirectParams" => ["id" => ""]
            ],
            "delete" => [
                "class" => "\common\actions\DeleteAction",
                "modelClass" => new MY_TaskArea(),
            ]
        ];
    }

    public function actionAjaxlist() {
        $res = MY_TaskArea::getList();
        $temp = ["total" => $res["total"], "rows" => []];
        if ($res["total"] > 0) {
            foreach ($res["data"] as $item) {
                $temp["rows"][] = [
                    "name" => $item["name"],
                    "updated_at" => Yii::$app->formatter->asDate($item["updated_at"]),
                    "action" => MTools::getStringActions([
                        "update" => [
                            "params" => [ "id" => $item["id"]],
                            "title" => "编辑"
                        ],
                        "delete" => [
                            "params" => [ "id" => $item["id"]],
                            "title" => "删除"
                        ]
                    ])
                ];
            }
        }
        echo Json::encode($temp);
    }

}
